$(function () {
    $("#jqGrid").jqGrid({
        url: '../customsettlement/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true ,hidden: true},
			{ label: '区域基数表id', name: 'areaBaseId', index: 'area_base_id', width: 80 ,
                formatter:function(v){
                  return  queryByIndex(v);
                } },
			{ label: '单位名称', name: 'unitName', index: 'unit_name', width: 80 }, 			
			{ label: '合同编号', name: 'contractNo', index: 'contract_no', width: 80 }, 			
			{ label: '结算点编码', name: 'settlementNo', index: 'settlement_no', width: 80 }, 			
			{ label: '结算点简码', name: 'settlementCode', index: 'settlement_code', width: 80 }, 			
			{ label: '结算点名称', name: 'settlementName', index: 'settlement_name', width: 80 }, 			
			{ label: '申报原则', name: 'principle', index: 'principle', width: 80 }, 			
			{ label: '滞后天数', name: 'delay', index: 'delay', width: 80 }, 			
			{ label: '是否需体检', name: 'healthCheckup', index: 'health_checkup', width: 80  ,formatter:function(v){
                if(v=="0"){
                    return "是";
                }else if(v=="1") {
                    return "否"
                }else{
                    return "";
                }
            }},
			{ label: '是否需求职登记录', name: 'jobRegistration', index: 'job_registration', width: 80 ,formatter:function(v){
                if(v=="1"){
                    return "是";
                }else if(v=="0") {
                    return "否"
                }else{
                    return "";
                }
            }},
			{ label: '是否需身份证', name: 'identityCard', index: 'identity_card', width: 80 , formatter:function(v){
                if(v=="1"){
                    return "是";
                }else if(v=="0") {
                    return "否"
                }else{
                    return "";
                }
            }},
			{ label: '是否需相片', name: 'picture', index: 'picture', width: 80  ,formatter:function(v){
                if(v=="1"){
                    return "是";
                }else if(v=="0") {
                    return "否"
                }else{
                    return "";
                }
            }},
			{ label: '是否需劳动合同', name: 'contract', index: 'contract', width: 80  ,formatter:function(v){
                if(v=="1"){
                    return "是";
                }else if(v=="0") {
                    return "否"
                }else{
                    return "";
                }
            }},
			{ label: '是否需员工手册签收单', name: 'ygscqsd', index: 'ygscqsd', width: 80 ,formatter:function(v){
                if(v=="1"){
                    return "是";
                }else if(v=="0") {
                    return "否"
                }else{
                    return "";
                }
            }},
            { label: '是否是华顺结算点', name: 'ishuashun', index: 'isHuashun', width: 80 ,formatter:function(v){
                if(v=="Y"){
                    return "是";
                }else if(v=="N") {
                    return "否"
                }else{
                    return "";
                }
            }},
			{ label: '是否需体检表', name: 'healthForm', index: 'health_form', width: 80 ,formatter:function(v){
                if(v=="1"){
                    return "是";
                }else if(v=="0") {
                    return "否"
                }else{
                    return "";
                }
            }},
			{ label: '员工核定基数', name: 'empBaseNum', index: 'emp_base_num', width: 80 }, 			
			{ label: '申报原则', name: 'declarPrinciple', index: 'declar_principle', width: 80 ,
                formatter:function(v){
                    if(v=="0"){
                        return "自动";
                    }else{
                        return "手动"
                    }
                } },
			{ label: '五险申报', name: 'fiveInsurance', index: 'five_insurance', width: 80,
				formatter:function(v){
                if(v=="0"){
                    return "自动";
                }else{
                    return "手动"
                }
            } },
			{ label: '工伤申报', name: 'injuryDeclar', index: 'injury_declar', width: 80 ,
                formatter:function(v){
                    if(v=="0"){
                        return "自动";
                    }else{
                        return "手动"
                    }
                } },
			{ label: '养老申报', name: 'pensionDeclar', index: 'pension_declar', width: 80 ,
                formatter:function(v){
                    if(v=="0"){
                        return "自动";
                    }else{
                        return "手动"
                    }
                } },
			{ label: '失业申报', name: 'unemploymentDeclar', index: 'unemployment_declar', width: 80 ,
                formatter:function(v){
                    if(v=="0"){
                        return "自动";
                    }else{
                        return "手动"
                    }
                } },
			{ label: '医疗申报', name: 'medicareClar', index: 'medicare_clar', width: 80 ,
                formatter:function(v){
                    if(v=="0"){
                        return "自动";
                    }else{
                        return "手动"
                    }
                } },
			{ label: '生育申报', name: 'maternityClar', index: 'maternity_clar', width: 80 ,
                formatter:function(v){
                    if(v=="0"){
                        return "自动";
                    }else{
                        return "手动"
                    }
                } },
			{ label: '公积金申报', name: 'accumulationFundDeclar', index: 'accumulation_fund_declar', width: 80 ,
                formatter:function(v){
                    if(v=="0"){
                        return "自动";
                    }else{
                        return "手动"
                    }
                } },
			{ label: '五险参保代码', name: 'fiveInsuranceCode', index: 'five_insurance_code', width: 80 }, 			
			{ label: '工伤参保代码', name: 'injuryDeclarCode', index: 'injury_declar_code', width: 80 }, 			
			{ label: '养老参保代码', name: 'pensionDeclarCode', index: 'pension_declar_code', width: 80 }, 			
			{ label: '失业参保代码', name: 'unemploymentDeclarCode', index: 'unemployment_declar_code', width: 80 }, 			
			{ label: '医疗参保代码', name: 'medicareClarCode', index: 'medicare_clar_code', width: 80 }, 			
			{ label: '生育参保代码', name: 'maternityClarCode', index: 'maternity_clar_code', width: 80 }, 			
			{ label: '公积金参保代码', name: 'accumulationFundDeclarCode', index: 'accumulation_fund_declar_code', width: 80 }, 			
			{ label: '工伤报退限制:25', name: 'injuryExitLimit', index: 'injury_exit_limit', width: 80 }, 			
			{ label: '结算模式', name: 'settlementMode', index: 'settlement_mode', width: 80,formatter: getDictInfo },
			{ label: '失业享受限制,多少天内', name: 'unemploymentEnjoyLimit', index: 'unemployment_enjoy_limit', width: 80 }, 			
			{ label: '入职档案移交时限，30', name: 'entryMoveLimit', index: 'entry_move_limit', width: 80 }, 			
			{ label: '离职档案移交时限，30', name: 'leaveMoveLimit', index: 'leave_move_limit', width: 80 }, 			
			{ label: '合同续签变更档案移交时限，30', name: 'contractMoveLimit', index: 'contract_move_limit', width: 80 }			
        ],
		viewrecords: true,
        height: $(window).height()*0.8,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        //字段太多自动加载横轴滚动条
        shrinkToFit:false,
        autoScroll: false,
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });


    var r = utils.getDictList("setlever");

    vm.dictList = r.setlever;
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q: {
            unitName: null
        },
		showList: true,
		title: null,
        areaBaseIdlist:{},
		arealist:{},
		deptlist:{},
		userlist:{},
        dictList:{},
		customSettlement: {},
        settleModeList:{}

	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
            vm.areaBaseIdlist = {};
            vm.arealist = {};
            vm.deptlist = {};
            vm.userlist = {};
			vm.customSettlement = {
                declarPrinciple:0,
                fiveInsurance:0,
				injuryDeclar:0,
				pensionDeclar:0,
				unemploymentDeclar:0,
				medicareClar:0,
				maternityClar:0,
				accumulationFundDeclar:0
			};
			vm.getListinfo();
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            vm.getListinfo();
            vm.getInfo(id);

		},
		saveOrUpdate: function (event) {
			var url = vm.customSettlement.id == null ? "../customsettlement/save" : "../customsettlement/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.customSettlement),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../customsettlement/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../customsettlement/info/"+id, function(r){
                vm.customSettlement = r.customSettlement;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'unit_name': vm.q.unitName},
                page:page
            }).trigger("reloadGrid");
		},
        getListinfo: function(){
            $.get("../customsettlement/getListinfo", function(r){
				vm.userlist = r.userlist;
				vm.deptlist = r.deptlist;
				vm.arealist = r.area;
                vm.areaBaseIdlist = r.areaBaseId;
                vm.settleModeList = r.settle_mode;
            });
        },
		qyformatter: function(code){
            $.get("../customsettlement/queryByIndex/"+code, function(r){
                     return r.indexToValue;
            });
		}

	}
});